<script type="text/javascript">
/*点击展开子分类
* id ID
* title 标题
* tabledir 数据表
*/
function display_child(id,title,tabledir){
    var html = ''; var hide_id = ''; var tree = '';
    var no_delete_sortid = '{$navModuleRs.no_delete_sortid}';
    var no_delete_sortid_arr = no_delete_sortid.split(',');
    $.ajax({
        type: "POST",
        url: "{:url('common/child')}",
        dataType: "json",
        data: {tabledir:tabledir, id:id},
        success: function(data){
            $.each(data,function(i,val){
                tree = '';
                for(var j=0;j<val.level;j++){
                    tree += '|---';
                }
                html += '<tr id="tr_'+val.id+'">';
                html += '    <td class="text-center">';
                html += '        <label class="form-check form-check-inline">';
                html += '            <input type="checkbox" name="selectid[]" id="selectid" value="'+val.id+'" class="mr-1" />';
                html += '            <span class="d-invisible">'+val.id+'</span>';
                html += '        </label>';
                html += '    </td>';
                if(val.child == 'yes'){
                    html += '    <td id="td_'+val.id+'"><a onclick="javascript:display_child('+val.id+',\''+val.title+'\',\''+tabledir+'\');" href="javascript:void(0);">'+tree+val.title+'<i class="fa fa-plus-square fa-lg ml-2"></i></a></td>';
                }else{
                    html += '    <td>'+tree+val.title+'</td>';
                }
                html += '    <td class="text-center d-invisible">';
                html += '        <input name="sequence[]" type="text" value="'+val.sequence+'" class="input" size="5" />';
                html += '    </td>';
                html += '    <td class="text-center">';
                html += '        <a href="{:url('/sort/edit',['lang'=>$lang])}&tabledir='+val.tabledir+'&id='+val.id+'" class="btn btn-success btn-sm mr-2 mb-2"><i class="fa fa-edit mr-1"></i>{:lang('v_edit')}</a>';
                if($.inArray(val.id,no_delete_sortid_arr) != '-1' && no_delete_sortid.length != 0){
                    html += '<span class="btn btn-sm btn-default mb-2 disabled"><i class="fa fa-ban mr-1"></i>{:lang('v_cannot_delete')}</span>';
                }else{
                    html += '<span onClick="javascript:do_confirm(\'\',\'\',\'{:url('/sort/delete_one',['lang'=>$lang])}&tabledir='+val.tabledir+'&id='+val.id+'\',\'\',\'\');" class="btn btn-danger btn-sm mb-2"><i class="fa fa-trash mr-1"></i>{:lang('v_delete')}</span>';
                }
                html += '    </td>';
                html += '</tr>';
                hide_id = val.hide_id;
            });
            $('#tr_'+id+'').after(html);
            var parent_tree = tree.substring(0,tree.length-4);
            $('#td_'+id+'').html('<a onclick="javascript:hide_child('+id+',\''+hide_id+'\',\''+title+'\',\''+parent_tree+'\',\''+tabledir+'\');" href="javascript:void(0);">'+parent_tree+title+'<i class="fa fa-plus-square fa-lg ml-2"></i></a>');
        }
    });
}
</script>
{include file="public/js_hide_child" /}